package com.boe.rnmf.pkg;

import java.util.concurrent.CountDownLatch;
import javax.sql.DataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableTransactionManagement
//@MapperScan(value = "com.boe.rnmf.pkg.mapper.*.*.*")
public class Application {

  @Bean
  public CountDownLatch closeLatch() {
    return new CountDownLatch(1);
  }

  public static void main(String[] args) throws InterruptedException {
    ApplicationContext ctx = SpringApplication.run(Application.class, args);
    CountDownLatch cdl = ctx.getBean(CountDownLatch.class);
    cdl.await();
  }

  @Bean
  public PlatformTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) {
    return new DataSourceTransactionManager(dataSource);
  }
}